#pragma once

#include "scope.h"
#include "ast.h"

class Sema // 语义分析
{
public:
    Sema(DiagEngine &diagEngine) : diagEngine(diagEngine) {}
    std::shared_ptr<ASTNode> SemaVariableDeclNode(Token token, CType* ty);
    std::shared_ptr<ASTNode> SemaVariableAccessNode(Token token);
    std::shared_ptr<ASTNode> SemaAssignExprNode(std::shared_ptr<ASTNode> left, std::shared_ptr<ASTNode> right, Token token);
    std::shared_ptr<ASTNode> SemaBinaryExprNode(std::shared_ptr<ASTNode> left, std::shared_ptr<ASTNode> right, OpCode op);
    std::shared_ptr<ASTNode> SemaIfStmtNode(std::shared_ptr<ASTNode> condNode, 
                                            std::shared_ptr<ASTNode> thenNode, 
                                            std::shared_ptr<ASTNode> elseNode);
    std::shared_ptr<ASTNode> SemaNumberExprNode(Token token, CType* ty);

    void EnterScope();
    void ExitScope();
    DiagEngine &GetDiaEngine() const
    {
        return diagEngine;
    }
private:
    Scope scope;
    DiagEngine &diagEngine;
};